package org.casaca.checkbackup.core.data;

import java.math.BigInteger;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

public abstract class SystemElement implements Comparable<SystemElement> {
	private BigInteger id;
	private String name;
	private String path;
	private Calendar createdAt;
	private Calendar modifiedAt;
	
	private Folder parent;
	private Map<String, String> checksums;
	
	private synchronized BigInteger getUniqueId(){
		return BigInteger.valueOf(System.currentTimeMillis());
	}
	
	public SystemElement(Folder parent, String name){
		if(parent==null || name==null)
			throw new IllegalArgumentException("Parent folder and name must not be null.");
		
		this.parent = parent;
		this.name = name;
		
		this.path = this.parent.getPath()+System.getProperty("file.separator")+name;
		
		this.id = getUniqueId();
		this.createdAt = null;
		this.modifiedAt = null;
		
		this.checksums = new HashMap<String, String>();
	}
	
	protected SystemElement(String path){
		java.io.File file = new java.io.File(path);
		this.name = file.getName();
		this.path = path;
		
		this.id = getUniqueId();
		this.createdAt = null;
		this.modifiedAt = null;
		
		this.checksums = new HashMap<String, String>();
	}

	public BigInteger getId() {
		return id;
	}

	public void setId(BigInteger id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Calendar getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(Calendar createdAt) {
		this.createdAt = createdAt;
	}

	public Calendar getModifiedAt() {
		return modifiedAt;
	}

	public void setModifiedAt(Calendar modifiedAt) {
		this.modifiedAt = modifiedAt;
	}

	public Folder getParent() {
		return parent;
	}

	public void setParent(Folder parent) {
		this.parent = parent;
	}
	
	public Map<String, String> getChecksums(){
		return this.checksums;
	}
	
	public String toString(){
		return this.path;
	}
	
	public abstract BigInteger getSize();
	
	public abstract void setSize(BigInteger size);
}